/*     */ package com.hp.bon.logreverse.start;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ 
/*     */ public class SimpleDeamonAppHelper
/*     */ {
/*     */   private static final String RUNNING_DIR = "./running";
/*     */   private String _main;
/*     */   private String _mainClassname;
/*     */   File fStop;
/*     */   File fRunning;
/*  62 */   int defaultSleepSecond = 2;
/*     */ 
/*     */   public SimpleDeamonAppHelper(String main)
/*     */   {
/*     */     try
/*     */     {
/*  41 */       if (main == null) {
/*  42 */         StackTraceElement[] es = Thread.currentThread().getStackTrace();
/*  43 */         this._mainClassname = (main = es[(es.length - 1)].getClassName());
/*     */       } else {
/*  45 */         this._mainClassname = main;
/*     */       }
/*  47 */       int i = main.lastIndexOf('.');
/*  48 */       if (i >= 0)
/*  49 */         this._main = main.substring(i + 1);
/*  50 */       this.fStop = new File("./running", this._mainClassname + ".stop");
/*  51 */       this.fRunning = new File("./running", this._mainClassname + ".running");
/*     */     } catch (Exception e) {
/*  53 */       e.printStackTrace();
/*  54 */       System.exit(-1);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void waitExit()
/*     */   {
/*  65 */     waitExit(this.defaultSleepSecond);
/*     */   }
/*     */ 
/*     */   public void waitExit(int second)
/*     */   {
/*  74 */     if ((this.fRunning.exists()) && (System.currentTimeMillis() - this.fRunning.lastModified() < this.defaultSleepSecond * 1000 * 2)) {
/*  75 */       System.out.println(this._main + " maybe running,please ensure it's status!\nIf it isn't running,please delete the file:" + this.fRunning.getAbsolutePath());
/*  76 */       System.exit(-2);
/*     */     }
/*  78 */     this.fStop.delete();
/*  79 */     System.out.print("Create running control file:" + this.fRunning.getAbsolutePath() + "...");
/*     */     try {
/*  81 */       this.fRunning.getParentFile().mkdirs();
/*  82 */       this.fRunning.createNewFile();
/*  83 */       System.out.println("It can be stopped by creating stop file " + this.fStop.getAbsolutePath() + " !");
/*     */     } catch (IOException ex) {
/*  85 */       System.out.println(this._main + ":create system file :" + this.fRunning.getAbsolutePath() + "ERROR");
/*  86 */       ex.printStackTrace();
/*  87 */       System.exit(-3);
/*     */     }
/*  89 */     this.fRunning.deleteOnExit();
/*  90 */     while (!this.fStop.exists()) {
/*     */       try {
/*  92 */         Thread.sleep(second * 1000);
/*     */       }
/*     */       catch (InterruptedException localInterruptedException) {
/*     */       }
/*  96 */       this.fRunning.setLastModified(System.currentTimeMillis());
/*     */     }
/*  98 */     System.out.println("Received a stop request. Exiting " + this._main + "...");
/*  99 */     this.fStop.delete();
/* 100 */     this.fRunning.delete();
/*     */ 
/* 102 */     File dir = new File("./running");
/* 103 */     String[] lists = dir.list();
/* 104 */     if ((lists == null) || (lists.length < 1))
/* 105 */       dir.delete();
/*     */   }
/*     */ 
/*     */   public void requestStop()
/*     */   {
/*     */     try
/*     */     {
/* 113 */       this.fStop.createNewFile();
/*     */     } catch (IOException e) {
/* 115 */       e.printStackTrace();
/* 116 */       System.out.println("Can NOT Create stop file " + this.fStop.getAbsolutePath() + "!");
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.logreverse.start.SimpleDeamonAppHelper
 * JD-Core Version:    0.6.1
 */